package com.xiaoxu.intranetweb.mybatisplusSzappdb.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xiaoxu.intranetweb.mybatisplusSzappdb.entity.TFactoryHandlingPersonnel;
import com.xiaoxu.intranetweb.mybatisplusSzappdb.entity.TFactoryProcessInfo;
import com.xiaoxu.intranetweb.mybatisplusSzappdb.mapper.TFactoryHandlingPersonnelMapper;
import com.xiaoxu.intranetweb.mybatisplusSzappdb.service.ITFactoryHandlingPersonnelService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaoxu.intranetweb.util.StringUtils;
import com.xiaoxu.intranetweb.util.SzResult;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xiaoxu
 * @since 2024-08-26
 */
@Service
public class TFactoryHandlingPersonnelServiceImpl extends ServiceImpl<TFactoryHandlingPersonnelMapper, TFactoryHandlingPersonnel> implements ITFactoryHandlingPersonnelService {

    @Override
    public SzResult addFactoryProcessInfo(TFactoryHandlingPersonnel factoryHandlingPersonnel) {
        QueryWrapper<TFactoryHandlingPersonnel> factoryHandlingPersonnelQueryWrapper = new QueryWrapper<>();
        factoryHandlingPersonnelQueryWrapper.eq("PDT_NAME",factoryHandlingPersonnel.getPdtName());
        if (getOne(factoryHandlingPersonnelQueryWrapper) != null) {
            return SzResult.error("该品种已重复");
        }
        return SzResult.success(save(factoryHandlingPersonnel));
    }

    @Override
    public SzResult updateFactoryProcessInfo(TFactoryHandlingPersonnel factoryHandlingPersonnel) {
        if (getById(factoryHandlingPersonnel.getId()).getPdtName().equals(factoryHandlingPersonnel.getPdtName())) {
            return SzResult.success(updateById(factoryHandlingPersonnel));
        }
        QueryWrapper<TFactoryHandlingPersonnel> factoryHandlingPersonnelQueryWrapper = new QueryWrapper<>();
        factoryHandlingPersonnelQueryWrapper.eq("PDT_NAME",factoryHandlingPersonnel.getPdtName());
        if (getOne(factoryHandlingPersonnelQueryWrapper) != null) {
            return SzResult.error("该品种已重复");
        }
        return SzResult.success(updateById(factoryHandlingPersonnel));
    }
}
